home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Information / Specifications / X⁄YMODEM / X⁄YMODEM spec
Text File  |  1994-05-07  |  65KB  |  1,981 lines

  1.  
  2.  
  3.  
  4.                                       - 1 -
  5.  
  6.  
  7.  
  8.                          XMODEM/YMODEM PROTOCOL REFERENCE
  9.                      A compendium of documents describing the
  10.  
  11.                                 XMODEM and YMODEM
  12.  
  13.                              File Transfer Protocols
  14.  
  15.  
  16.  
  17.  
  18.                       This document was formatted 10-27-87.
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.                              Edited by Chuck Forsberg
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.                      Please distribute as widely as possible.
  40.  
  41.                            Questions to Chuck Forsberg
  42.  
  43.  
  44.  
  45.  
  46.  
  47.                                Omen Technology Inc
  48.                           The High Reliability Software
  49.                             17505-V Sauvie Island Road
  50.                               Portland Oregon 97231
  51.                             VOICE: 503-621-3406 :VOICE
  52.     Modem (TeleGodzilla): 503-621-3746 Speed 19200(Telebit PEP),2400,1200,300
  53.                               CompuServe: 70007,2304
  54.                                     GEnie: CAF
  55.                         UUCP: ...!tektronix!reed!omen!caf
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.                                       - 2 -
  71.  
  72.  
  73.  
  74.     1.  TOWER OF BABEL
  75.  
  76.     A "YMODEM Tower of Babel" has descended on the microcomputing community
  77.     bringing with it confusion, frustration, bloated phone bills, and wasted
  78.     man hours.  Sadly, I (Chuck Forsberg) am partly to blame for this mess.
  79.  
  80.     As author of the early 1980s batch and 1k XMODEM extensions, I assumed
  81.     readers of earlier versions of this document would implement as much of
  82.     the YMODEM protocol as their programming skills and computing environments
  83.     would permit.  This proved a rather naive assumption as programmers
  84.     motivated by competitive pressure implemented as little of YMODEM as
  85.     possible.  Some have taken whatever parts of YMODEM that appealed to them,
  86.     applied them to MODEM7 Batch, Telink, XMODEM or whatever, and called the
  87.     result YMODEM.
  88.  
  89.     Jeff Garbers (Crosstalk package development director) said it all: "With
  90.     protocols in the public domain, anyone who wants to dink around with them
  91.     can go ahead." [1]
  92.  
  93.     Documents containing altered examples derived from YMODEM.DOC have added
  94.     to the confusion.  In one instance, the heading in YMODEM.DOC's Figure 1
  95.     has mutated from "1024 byte Packets" to "YMODEM/CRC File Transfer
  96.     Protocol".  None of the XMODEM and YMODEM examples shown in that document
  97.     were correct.
  98.  
  99.     To put an end to this confusion, we must make "perfectly clear" what
  100.     YMODEM stands for, as Ward Christensen defined it in his 1985 coining of
  101.     the term.
  102.  
  103.     To the majority of you who read, understood, and respected Ward's
  104.     definition of YMODEM, I apologize for the inconvenience.
  105.  
  106.     1.1  Definitions
  107.  
  108.     ARC     ARC is a program that compresses one or more files into an archive
  109.             and extracts files from such archives.
  110.  
  111.     XMODEM  refers to the file transfer etiquette introduced by Ward
  112.             Christensen's 1977 MODEM.ASM program.  The name XMODEM comes from
  113.             Keith Petersen's XMODEM.ASM program, an adaptation of MODEM.ASM
  114.             for Remote CP/M (RCPM) systems.  It's also called the MODEM or
  115.             MODEM2 protocol.  Some who are unaware of MODEM7's unusual batch
  116.             file mode call it MODEM7.  Other aliases include "CP/M Users'
  117.             Group" and "TERM II FTP 3".  The name XMODEM caught on partly
  118.             because it is distinctive and partly because of media interest in
  119.  
  120.  
  121.     __________
  122.  
  123.      1. Page C/12, PC-WEEK July 12, 1987
  124.  
  125.  
  126.  
  127.  
  128.     Chapter 1
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.     X/YMODEM Protocol Reference      10-27-87                                3
  137.  
  138.  
  139.  
  140.             bulletin board and RCPM systems where it was accessed with an
  141.             "XMODEM" command.  This protocol is supported by every serious
  142.             communications program because of its universality, simplicity,
  143.             and reasonable performance.
  144.  
  145.     XMODEM/CRC replaces XMODEM's 1 byte checksum with a two byte Cyclical
  146.             Redundancy Check (CRC-16), giving modern error detection
  147.             protection.
  148.  
  149.     XMODEM-1k Refers to the XMODEM/CRC protocol with 1024 byte data blocks.
  150.  
  151.     YMODEM  Refers to the XMODEM/CRC (optional 1k blocks) protocol with batch
  152.             transmission as described below.  In a nutshell, YMODEM means
  153.             BATCH.
  154.  
  155.     YMODEM-g Refers to the streaming YMODEM variation described below.
  156.  
  157.     True YMODEM(TM) In an attempt to sort out the YMODEM Tower of Babel, Omen
  158.             Technology has trademarked the term True YMODEM(TM) to represent
  159.             the complete YMODEM protocol described in this document, including
  160.             pathname, length, and modification date transmitted in block 0.
  161.             Please contact Omen Technology about certifying programs for True
  162.             YMODEM(TM) compliance.
  163.  
  164.     ZMODEM  uses familiar XMODEM/CRC and YMODEM technology in a new protocol
  165.             that provides reliability, throughput, file management, and user
  166.             amenities appropriate to contemporary data communications.
  167.  
  168.     ZOO     Like ARC, ZOO is a program that compresses one or more files into
  169.             a "zoo archive".  ZOO supports many different operating systems
  170.             including Unix and VMS.
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.     Chapter 1
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.     X/YMODEM Protocol Reference      10-27-87                                4
  203.  
  204.  
  205.  
  206.     2.  YMODEM MINIMUM REQUIREMENTS
  207.  
  208.     All programs claiming to support YMODEM must meet the following minimum
  209.     requirements:
  210.  
  211.        + The sending program shall send the pathname (file name) in block 0.
  212.  
  213.        + The pathname shall be a null terminated ASCII string as described
  214.          below.
  215.  
  216.        + The receiving program shall use this pathname for the received file
  217.          name, unless explicitly overridden.
  218.  
  219.        + The sending program shall use CRC-16 in response to a "C" pathname
  220.          nak, otherwise use 8 bit checksum.
  221.  
  222.        + The receiving program must accept any mixture of 128 and 1024 byte
  223.          blocks within each file it receives.  Sending programs may switch
  224.          between 1024 and 128 byte blocks at the end of file(s), and when the
  225.          frequency of retransmissions so suggests.
  226.  
  227.        + The sending program must not change the length of an unacknowledged
  228.          block.
  229.  
  230.        + At the end of each file, the sending program shall send EOT up to ten
  231.          times until it receives an ACK character.  (This is part of the
  232.          XMODEM spec.)
  233.  
  234.        + The end of a transfer session shall be signified by a null (empty)
  235.          pathname.
  236.  
  237.     Programs not meeting all of these requirements are not YMODEM compatible,
  238.     and shall not be described as supporting YMODEM.
  239.  
  240.     Meeting these MINIMUM requirements does not guarantee reliable file
  241.     transfers under stress.  Particular attention is called to XMODEM's single
  242.     character supervisory messages that are easily corrupted by transmission
  243.     errors.
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.     Chapter 2
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.     X/YMODEM Protocol Reference      10-27-87                                5
  269.  
  270.  
  271.  
  272.     3.  WHY YMODEM?
  273.  
  274.     Since its development half a decade ago, the Ward Christensen modem
  275.     protocol has enabled a wide variety of computer systems to interchange
  276.     data.  There is hardly a communications program that doesn't at least
  277.     claim to support this protocol.
  278.  
  279.     Advances in computing, modems and networking have revealed a number of
  280.     weaknesses in the original protocol:
  281.  
  282.        + The short block length caused throughput to suffer when used with
  283.          timesharing systems, packet switched networks, satellite circuits,
  284.          and buffered (error correcting) modems.
  285.  
  286.        + The 8 bit arithmetic checksum and other aspects allowed line
  287.          impairments to interfere with dependable, accurate transfers.
  288.  
  289.        + Only one file could be sent per command.  The file name had to be
  290.          given twice, first to the sending program and then again to the
  291.          receiving program.
  292.  
  293.        + The transmitted file could accumulate as many as 127 extraneous
  294.          bytes.
  295.  
  296.        + The modification date of the file was lost.
  297.  
  298.     A number of other protocols have been developed over the years, but none
  299.     have displaced XMODEM to date:
  300.  
  301.        + Lack of public domain documentation and example programs have kept
  302.          proprietary protocols such as Blast, Relay, and others tightly bound
  303.          to the fortunes of their suppliers.
  304.  
  305.        + Complexity discourages the widespread application of BISYNC, SDLC,
  306.          HDLC, X.25, and X.PC protocols.
  307.  
  308.        + Performance compromises and complexity have limited the popularity of
  309.          the Kermit protocol, which was developed to allow file transfers in
  310.          environments hostile to XMODEM.
  311.  
  312.     The XMODEM protocol extensions and YMODEM Batch address some of these
  313.     weaknesses while maintaining most of XMODEM's simplicity.
  314.  
  315.     YMODEM is supported by the public domain programs YAM (CP/M),
  316.     YAM(CP/M-86), YAM(CCPM-86), IMP (CP/M), KMD (CP/M), rz/sz (Unix, Xenix,
  317.     VMS, Berkeley Unix, Venix, Xenix, Coherent, IDRIS, Regulus).  Commercial
  318.     implementations include MIRROR, and Professional-YAM.[1] Communications
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.     Chapter 3
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.     X/YMODEM Protocol Reference      10-27-87                                6
  335.  
  336.  
  337.  
  338.     programs supporting these extensions have been in use since 1981.
  339.  
  340.     The 1k block length (XMODEM-1k) described below may be used in conjunction
  341.     with YMODEM Batch Protocol, or with single file transfers identical to the
  342.     XMODEM/CRC protocol except for minimal changes to support 1k blocks.
  343.  
  344.     Another extension is the YMODEM-g protocol.  YMODEM-g provides batch
  345.     transfers with maximum throughput when used with end to end error
  346.     correcting media, such as X.PC and error correcting modems, including 9600
  347.     bps units by TeleBit, U.S.Robotics, Hayes, Electronic Vaults, Data Race,
  348.     and others.
  349.  
  350.     To complete this tome, edited versions of Ward Christensen's original
  351.     protocol document and John Byrns's CRC-16 document are included for
  352.     reference.
  353.  
  354.     References to the MODEM or MODEM7 protocol have been changed to XMODEM to
  355.     accommodate the vernacular.  In Australia, it is properly called the
  356.     Christensen Protocol.
  357.  
  358.  
  359.     3.1  Some Messages from the Pioneer
  360.  
  361.     #: 130940 S0/Communications 25-Apr-85  18:38:47
  362.     Sb: my protocol
  363.     Fm: Ward Christensen 76703,302 [2]
  364.     To: all
  365.  
  366.     Be aware the article[3] DID quote me correctly in terms of the phrases
  367.     like "not robust", etc.
  368.  
  369.     It was a quick hack I threw together, very unplanned (like everything I
  370.     do), to satisfy a personal need to communicate with "some other" people.
  371.  
  372.     ONLY the fact that it was done in 8/77, and that I put it in the public
  373.     domain immediately, made it become the standard that it is.
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.     __________________________________________________________________________
  382.  
  383.      1. Available for IBM PC,XT,AT, Unix and Xenix
  384.  
  385.      2. Edited for typesetting appearance
  386.  
  387.      3. Infoworld April 29 p. 16
  388.  
  389.  
  390.  
  391.  
  392.     Chapter 3
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.     X/YMODEM Protocol Reference      10-27-87                                7
  401.  
  402.  
  403.  
  404.     I think its time for me to
  405.  
  406.     (1) document it; (people call me and say "my product is going to include
  407.     it - what can I 'reference'", or "I'm writing a paper on it, what do I put
  408.     in the bibliography") and
  409.  
  410.     (2) propose an "incremental extension" to it, which might take "exactly"
  411.     the form of Chuck Forsberg's YAM protocol.  He wrote YAM in C for CP/M and
  412.     put it in the public domain, and wrote a batch protocol for Unix[4] called
  413.     rb and sb (receive batch, send batch), which was basically XMODEM with
  414.        (a) a record 0 containing filename date time and size
  415.        (b) a 1K block size option
  416.        (c) CRC-16.
  417.  
  418.     He did some clever programming to detect false ACK or EOT, but basically
  419.     left them the same.
  420.  
  421.     People who suggest I make SIGNIFICANT changes to the protocol, such as
  422.     "full duplex", "multiple outstanding blocks", "multiple destinations", etc
  423.     etc don't understand that the incredible simplicity of the protocol is one
  424.     of the reasons it survived to this day in as many machines and programs as
  425.     it may be found in!
  426.  
  427.     Consider the PC-NET group back in '77 or so - documenting to beat the band
  428.     - THEY had a protocol, but it was "extremely complex", because it tried to
  429.     be "all things to all people" - i.e. send binary files on a 7-bit system,
  430.     etc.  I was not that "benevolent". I (emphasize > I < ) had an 8-bit UART,
  431.     so "my protocol was an 8-bit protocol", and I would just say "sorry" to
  432.     people who were held back by 7-bit limitations.  ...
  433.  
  434.     Block size: Chuck Forsberg created an extension of my protocol, called
  435.     YAM, which is also supported via his public domain programs for UNIX
  436.     called rb and sb - receive batch and send batch.  They cleverly send a
  437.     "block 0" which contains the filename, date, time, and size.
  438.     Unfortunately, its UNIX style, and is a bit weird[5] - octal numbers, etc.
  439.     BUT, it is a nice way to overcome the kludgy "echo the chars of the name"
  440.     introduced with MODEM7.  Further, chuck uses CRC-16 and optional 1K
  441.     blocks.  Thus the record 0, 1K, and CRC, make it a "pretty slick new
  442.     protocol" which is not significantly different from my own.
  443.  
  444.     Also, there is a catchy name - YMODEM.  That means to some that it is the
  445.     "next thing after XMODEM", and to others that it is the Y(am)MODEM
  446.  
  447.  
  448.     __________
  449.  
  450.      4. VAX/VMS versions of these programs are also available.
  451.  
  452.      5. The file length, time, and file mode are optional.  The pathname and
  453.         file length may be sent alone if desired.
  454.  
  455.  
  456.  
  457.  
  458.     Chapter 3
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.     X/YMODEM Protocol Reference      10-27-87                                8
  467.  
  468.  
  469.  
  470.     protocol.  I don't want to emphasize that too much - out of fear that
  471.     other mfgrs might think it is a "competitive" protocol, rather than an
  472.     "unaffiliated" protocol.  Chuck is currently selling a much-enhanced
  473.     version of his CP/M-80 C program YAM, calling it Professional Yam, and its
  474.     for the PC - I'm using it right now.  VERY slick!  32K capture buffer,
  475.     script, scrolling, previously captured text search, plus built-in commands
  476.     for just about everything - directory (sorted every which way), XMODEM,
  477.     YMODEM, KERMIT, and ASCII file upload/download, etc.  You can program it
  478.     to "behave" with most any system - for example when trying a number for
  479.     CIS it detects the "busy" string back from the modem and substitutes a
  480.     diff phone # into the dialing string and branches back to try it.
  481.  
  482.  
  483.  
  484.  
  485.  
  486.  
  487.  
  488.  
  489.  
  490.  
  491.  
  492.  
  493.  
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.     Chapter 3
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.     X/YMODEM Protocol Reference      10-27-87                                9
  533.  
  534.  
  535.  
  536.     4.  XMODEM PROTOCOL ENHANCEMENTS
  537.  
  538.     This chapter discusses the protocol extensions to Ward Christensen's 1982
  539.     XMODEM protocol description document.
  540.  
  541.     The original document recommends the user be asked whether to continue
  542.     trying or abort after 10 retries.  Most programs no longer ask the
  543.     operator whether he wishes to keep retrying.  Virtually all correctable
  544.     errors are corrected within the first few retransmissions.  If the line is
  545.     so bad that ten attempts are insufficient, there is a significant danger
  546.     of undetected errors.  If the connection is that bad, it's better to
  547.     redial for a better connection, or mail a floppy disk.
  548.  
  549.  
  550.     4.1  Graceful Abort
  551.  
  552.     The YAM and Professional-YAM X/YMODEM routines recognize a sequence of two
  553.     consecutive CAN (Hex 18) characters without modem errors (overrun,
  554.     framing, etc.) as a transfer abort command.  This sequence is recognized
  555.     when is waiting for the beginning of a block or for an acknowledgement to
  556.     a block that has been sent.  The check for two consecutive CAN characters
  557.     reduces the number of transfers aborted by line hits.  YAM sends eight CAN
  558.     characters when it aborts an XMODEM, YMODEM, or ZMODEM protocol file
  559.     transfer.  Pro-YAM then sends eight backspaces to delete the CAN
  560.     characters from the remote's keyboard input buffer, in case the remote had
  561.     already aborted the transfer and was awaiting a keyboarded command.
  562.  
  563.  
  564.     4.2  CRC-16 Option
  565.  
  566.     The XMODEM protocol uses an optional two character CRC-16 instead of the
  567.     one character arithmetic checksum used by the original protocol and by
  568.     most commercial implementations.  CRC-16 guarantees detection of all
  569.     single and double bit errors,  all errors with an odd number of error
  570.     bits, all burst errors of length 16 or less, 99.9969% of all 17-bit error
  571.     bursts, and 99.9984 per cent of all possible longer error bursts.  By
  572.     contrast, a double bit error, or a burst error of 9 bits or more can sneak
  573.     past the XMODEM protocol arithmetic checksum.
  574.  
  575.     The XMODEM/CRC protocol is similar to the XMODEM protocol, except that the
  576.     receiver specifies CRC-16 by sending C (Hex 43) instead of NAK when
  577.     requesting the FIRST block.  A two byte CRC is sent in place of the one
  578.     byte arithmetic checksum.
  579.  
  580.     YAM's c option to the r command enables CRC-16 in single file reception,
  581.     corresponding to the original implementation in the MODEM7 series
  582.     programs.  This remains the default because many commercial communications
  583.     programs and bulletin board systems still do not support CRC-16,
  584.     especially those written in Basic or Pascal.
  585.  
  586.     XMODEM protocol with CRC is accurate provided both sender and receiver
  587.  
  588.  
  589.  
  590.     Chapter 4                                     XMODEM Protocol Enhancements
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.     X/YMODEM Protocol Reference      10-27-87                               10
  599.  
  600.  
  601.  
  602.     both report a successful transmission.  The protocol is robust in the
  603.     presence of characters lost by buffer overloading on timesharing systems.
  604.  
  605.     The single character ACK/NAK responses generated by the receiving program
  606.     adapt well to split speed modems, where the reverse channel is limited to
  607.     ten per cent or less of the main channel's speed.
  608.  
  609.     XMODEM and YMODEM are half duplex protocols which do not attempt to
  610.     transmit information and control signals in both directions at the same
  611.     time.  This avoids buffer overrun problems that have been reported by
  612.     users attempting to exploit full duplex asynchronous file transfer
  613.     protocols such as Blast.
  614.  
  615.     Professional-YAM adds several proprietary logic enhancements to XMODEM's
  616.     error detection and recovery.  These compatible enhancements eliminate
  617.     most of the bad file transfers other programs make when using the XMODEM
  618.     protocol under less than ideal conditions.
  619.  
  620.  
  621.     4.3  XMODEM-1k 1024 Byte Block
  622.  
  623.     Disappointing throughput downloading from Unix with YMODEM[1] lead to the
  624.     development of 1024 byte blocks in 1982.  1024 byte blocks reduce the
  625.     effect of delays from timesharing systems, modems, and packet switched
  626.     networks on throughput by 87.5 per cent in addition to decreasing XMODEM's
  627.     per byte overhead 3 per cent on long files.
  628.  
  629.     The choice to use 1024 byte blocks is expressed to the sending program on
  630.     its command line or selection menu.[2] 1024 byte blocks improve throughput
  631.     in many applications, but some environments cannot accept 1024 byte
  632.     bursts, especially minicomputers running 19.2kb ports.
  633.  
  634.     An STX (02) replaces the SOH (01) at the beginning of the transmitted
  635.     block to notify the receiver of the longer block length.  The transmitted
  636.     block contains 1024 bytes of data.  The receiver should be able to accept
  637.     any mixture of 128 and 1024 byte blocks.  The block number (in the second
  638.     and third bytes of the block) is incremented by one for each block
  639.     regardless of the block length.
  640.  
  641.     The sender must not change between 128 and 1024 byte block lengths if it
  642.     has not received a valid ACK for the current block.  Failure to observe
  643.     this restriction allows transmission errors to pass undetected.
  644.  
  645.  
  646.  
  647.     __________
  648.  
  649.      1. The name hadn't been coined yet, but the protocol was the same.
  650.  
  651.      2. See "KMD/IMP Exceptions to YMODEM" below.
  652.  
  653.  
  654.  
  655.  
  656.     Chapter 4                                     XMODEM Protocol Enhancements
  657.  
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.     X/YMODEM Protocol Reference      10-27-87                               11
  665.  
  666.  
  667.  
  668.     If 1024 byte blocks are being used, it is possible for a file to "grow" up
  669.     to the next multiple of 1024 bytes.  This does not waste disk space if the
  670.     allocation granularity is 1k or greater.  With YMODEM batch transmission,
  671.     the optional file length transmitted in the file name block allows the
  672.     receiver to discard the padding, preserving the exact file length and
  673.     contents.
  674.  
  675.     1024 byte blocks may be used with batch file transmission or with single
  676.     file transmission.  CRC-16 should be used with the k option to preserve
  677.     data integrity over phone lines.  If a program wishes to enforce this
  678.     recommendation, it should cancel the transfer, then issue an informative
  679.     diagnostic message if the receiver requests checksum instead of CRC-16.
  680.  
  681.     Under no circumstances may a sending program use CRC-16 unless the
  682.     receiver commands CRC-16.
  683.  
  684.               Figure 1.  XMODEM-1k Blocks
  685.  
  686.               SENDER                                  RECEIVER
  687.                                                       "s -k foo.bar"
  688.               "foo.bar open x.x minutes"
  689.                                                       C
  690.               STX 01 FE Data[1024] CRC CRC
  691.                                                       ACK
  692.               STX 02 FD Data[1024] CRC CRC
  693.                                                       ACK
  694.               STX 03 FC Data[1000] CPMEOF[24] CRC CRC
  695.                                                       ACK
  696.               EOT
  697.                                                       ACK
  698.  
  699.               Figure 2.  Mixed 1024 and 128 byte Blocks
  700.  
  701.               SENDER                                  RECEIVER
  702.                                                       "s -k foo.bar"
  703.               "foo.bar open x.x minutes"
  704.                                                       C
  705.               STX 01 FE Data[1024] CRC CRC
  706.                                                       ACK
  707.               STX 02 FD Data[1024] CRC CRC
  708.                                                       ACK
  709.               SOH 03 FC Data[128] CRC CRC
  710.                                                       ACK
  711.               SOH 04 FB Data[100] CPMEOF[28] CRC CRC
  712.                                                       ACK
  713.               EOT
  714.                                                       ACK
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722.     Chapter 4                                     XMODEM Protocol Enhancements
  723.  
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.     X/YMODEM Protocol Reference      10-27-87                               12
  731.  
  732.  
  733.  
  734.     5.  YMODEM Batch File Transmission
  735.  
  736.     The YMODEM Batch protocol is an extension to the XMODEM/CRC protocol that
  737.     allows 0 or more files to be transmitted with a single command.  (Zero
  738.     files may be sent if none of the requested files is accessible.) The
  739.     design approach of the YMODEM Batch protocol is to use the normal routines
  740.     for sending and receiving XMODEM blocks in a layered fashion similar to
  741.     packet switching methods.
  742.  
  743.     Why was it necessary to design a new batch protocol when one already
  744.     existed in MODEM7?[1] The batch file mode used by MODEM7 is unsuitable
  745.     because it does not permit full pathnames, file length, file date, or
  746.     other attribute information to be transmitted.  Such a restrictive design,
  747.     hastily implemented with only CP/M in mind, would not have permitted
  748.     extensions to current areas of personal computing such as Unix, DOS, and
  749.     object oriented systems.  In addition, the MODEM7 batch file mode is
  750.     somewhat susceptible to transmission impairments.
  751.  
  752.     As in the case of single a file transfer, the receiver initiates batch
  753.     file transmission by sending a "C" character (for CRC-16).
  754.  
  755.     The sender opens the first file and sends block number 0 with the
  756.     following information.[2]
  757.  
  758.     Only the pathname (file name) part is required for batch transfers.
  759.  
  760.     To maintain upwards compatibility, all unused bytes in block 0 must be set
  761.     to null.
  762.  
  763.     Pathname The pathname (conventionally, the file name) is sent as a null
  764.          terminated ASCII string.  This is the filename format used by the
  765.          handle oriented MSDOS(TM) functions and C library fopen functions.
  766.          An assembly language example follows:
  767.                                   DB      'foo.bar',0
  768.          No spaces are included in the pathname.  Normally only the file name
  769.          stem (no directory prefix) is transmitted unless the sender has
  770.          selected YAM's f option to send the full pathname.  The source drive
  771.          (A:, B:, etc.) is not sent.
  772.  
  773.          Filename Considerations:
  774.  
  775.  
  776.  
  777.     __________
  778.  
  779.      1. The MODEM7 batch protocol transmitted CP/M FCB bytes f1...f8 and
  780.         t1...t3 one character at a time.  The receiver echoed these bytes as
  781.         received, one at a time.
  782.  
  783.      2. Only the data part of the block is described here.
  784.  
  785.  
  786.  
  787.  
  788.     Chapter 5                                     XMODEM Protocol Enhancements
  789.  
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.     X/YMODEM Protocol Reference      10-27-87                               13
  797.  
  798.  
  799.  
  800.             + File names are forced to lower case unless the sending system
  801.               supports upper/lower case file names.  This is a convenience for
  802.               users of systems (such as Unix) which store filenames in upper
  803.               and lower case.
  804.  
  805.             + The receiver should accommodate file names in lower and upper
  806.               case.
  807.  
  808.             + When transmitting files between different operating systems,
  809.               file names must be acceptable to both the sender and receiving
  810.               operating systems.
  811.  
  812.          If directories are included, they are delimited by /; i.e.,
  813.          "subdir/foo" is acceptable, "subdir\foo" is not.
  814.  
  815.     Length The file length and each of the succeeding fields are optional.[3]
  816.          The length field is stored in the block as a decimal string counting
  817.          the number of data bytes in the file.  The file length does not
  818.          include any CPMEOF (^Z) or other garbage characters used to pad the
  819.          last block.
  820.  
  821.          If the file being transmitted is growing during transmission, the
  822.          length field should be set to at least the final expected file
  823.          length, or not sent.
  824.  
  825.          The receiver stores the specified number of characters, discarding
  826.          any padding added by the sender to fill up the last block.
  827.  
  828.     Modification Date The mod date is optional, and the filename and length
  829.          may be sent without requiring the mod date to be sent.
  830.  
  831.          Iff the modification date is sent, a single space separates the
  832.          modification date from the file length.
  833.  
  834.          The mod date is sent as an octal number giving the time the contents
  835.          of the file were last changed, measured in seconds from Jan 1 1970
  836.          Universal Coordinated Time (GMT).  A date of 0 implies the
  837.          modification date is unknown and should be left as the date the file
  838.          is received.
  839.  
  840.          This standard format was chosen to eliminate ambiguities arising from
  841.          transfers between different time zones.
  842.  
  843.  
  844.  
  845.  
  846.  
  847.     __________
  848.  
  849.      3. Fields may not be skipped.
  850.  
  851.  
  852.  
  853.  
  854.     Chapter 5                                     XMODEM Protocol Enhancements
  855.  
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.     X/YMODEM Protocol Reference      10-27-87                               14
  863.  
  864.  
  865.  
  866.     Mode Iff the file mode is sent, a single space separates the file mode
  867.          from the modification date.  The file mode is stored as an octal
  868.          string.  Unless the file originated from a Unix system, the file mode
  869.          is set to 0.  rb(1) checks the file mode for the 0x8000 bit which
  870.          indicates a Unix type regular file.  Files with the 0x8000 bit set
  871.          are assumed to have been sent from another Unix (or similar) system
  872.          which uses the same file conventions.  Such files are not translated
  873.          in any way.
  874.  
  875.  
  876.     Serial Number Iff the serial number is sent, a single space separates the
  877.          serial number from the file mode.  The serial number of the
  878.          transmitting program is stored as an octal string.  Programs which do
  879.          not have a serial number should omit this field, or set it to 0.  The
  880.          receiver's use of this field is optional.
  881.  
  882.  
  883.     Other Fields YMODEM was designed to allow additional header fields to be
  884.          added as above without creating compatibility problems with older
  885.          YMODEM programs.  Please contact Omen Technology if other fields are
  886.          needed for special application requirements.
  887.  
  888.     The rest of the block is set to nulls.  This is essential to preserve
  889.     upward compatibility.[4]
  890.  
  891.     If the filename block is received with a CRC or other error, a
  892.     retransmission is requested.  After the filename block has been received,
  893.     it is ACK'ed if the write open is successful.  If the file cannot be
  894.     opened for writing, the receiver cancels the transfer with CAN characters
  895.     as described above.
  896.  
  897.     The receiver then initiates transfer of the file contents according to the
  898.     standard XMODEM/CRC protocol.
  899.  
  900.     After the file contents have been transmitted, the receiver again asks for
  901.     the next pathname.
  902.  
  903.     Transmission of a null pathname terminates batch file transmission.
  904.  
  905.     Note that transmission of no files is not necessarily an error.  This is
  906.     possible if none of the files requested of the sender could be opened for
  907.     reading.
  908.  
  909.  
  910.  
  911.     __________
  912.  
  913.      4. If, perchance, this information extends beyond 128 bytes (possible
  914.         with Unix 4.2 BSD extended file names), the block should be sent as a
  915.         1k block as described above.
  916.  
  917.  
  918.  
  919.  
  920.     Chapter 5                                     XMODEM Protocol Enhancements
  921.  
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.     X/YMODEM Protocol Reference      10-27-87                               15
  929.  
  930.  
  931.  
  932.     The YMODEM receiver requests CRC-16 by default.
  933.  
  934.     The Unix programs sz(1) and rz(1) included in the source code file
  935.     RZSZ.ZOO should answer other questions about YMODEM batch protocol.
  936.  
  937.               Figure 3.  YMODEM Batch Transmission Session
  938.  
  939.               SENDER                                  RECEIVER
  940.                                                       "sb foo.*<CR>"
  941.               "sending in batch mode etc."
  942.                                                       C (command:rb)
  943.               SOH 00 FF foo.c NUL[123] CRC CRC
  944.                                                       ACK
  945.                                                       C
  946.               SOH 01 FE Data[128] CRC CRC
  947.                                                       ACK
  948.               SOH 03 FC Data[128] CRC CRC
  949.                                                       ACK
  950.               SOH 04 FB Data[100] CPMEOF[28] CRC CRC
  951.                                                       ACK
  952.               EOT
  953.                                                       NAK
  954.               EOT
  955.                                                       ACK
  956.                                                       C
  957.               SOH 00 FF NUL[128] CRC CRC
  958.                                                       ACK
  959.  
  960.             Figure 4.  YMODEM Batch Transmission Session-1k Blocks
  961.  
  962.             SENDER                                  RECEIVER
  963.                                                     "sb -k foo.*<CR>"
  964.             "sending in batch mode etc."
  965.                                                     C (command:rb)
  966.             SOH 00 FF foo.c NUL[123] CRC CRC
  967.                                                     ACK
  968.                                                     C
  969.             STX 02 FD Data[1024] CRC CRC
  970.                                                     ACK
  971.             SOH 03 FC Data[128] CRC CRC
  972.                                                     ACK
  973.             SOH 04 FB Data[100] CPMEOF[28] CRC CRC
  974.                                                     ACK
  975.             EOT
  976.                                                     NAK
  977.             EOT
  978.                                                     ACK
  979.                                                     C
  980.             SOH 00 FF NUL[128] CRC CRC
  981.                                                     ACK
  982.  
  983.  
  984.  
  985.  
  986.     Chapter 5                                     XMODEM Protocol Enhancements
  987.  
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.     X/YMODEM Protocol Reference      10-27-87                               16
  995.  
  996.  
  997.  
  998.            Figure 5.  YMODEM Filename block transmitted by sz
  999.  
  1000.            -rw-r--r--  6347 Jun 17 1984 20:34 bbcsched.txt
  1001.  
  1002.            00 0100FF62 62637363 6865642E 74787400   |...bbcsched.txt.|
  1003.            10 36333437 20333331 34373432 35313320   |6347 3314742513 |
  1004.            20 31303036 34340000 00000000 00000000   |100644..........|
  1005.            30 00000000 00000000 00000000 00000000
  1006.            40 00000000 00000000 00000000 00000000
  1007.            50 00000000 00000000 00000000 00000000
  1008.            60 00000000 00000000 00000000 00000000
  1009.            70 00000000 00000000 00000000 00000000
  1010.            80 000000CA 56
  1011.  
  1012.                 Figure 6.  YMODEM Header Information and Features
  1013.  
  1014.     _____________________________________________________________
  1015.     | Program   | Length | Date | Mode | S/N | 1k-Blk | YMODEM-g |
  1016.     |___________|________|______|______|_____|________|__________|
  1017.     |Unix rz/sz | yes    | yes  | yes  | no  | yes    | sb only  |
  1018.     |___________|________|______|______|_____|________|__________|
  1019.     |VMS rb/sb  | yes    | no   | no   | no  | yes    | no       |
  1020.     |___________|________|______|______|_____|________|__________|
  1021.     |Pro-YAM    | yes    | yes  | no   | yes | yes    | yes      |
  1022.     |___________|________|______|______|_____|________|__________|
  1023.     |CP/M YAM   | no     | no   | no   | no  | yes    | no       |
  1024.     |___________|________|______|______|_____|________|__________|
  1025.     |KMD/IMP    | ?      | no   | no   | no  | yes    | no       |
  1026.     |___________|________|______|______|_____|________|__________|
  1027.  
  1028.     5.1  KMD/IMP Exceptions to YMODEM
  1029.  
  1030.     KMD and IMP use a "CK" character sequence emitted by the receiver to
  1031.     trigger the use of 1024 byte blocks as an alternative to specifying this
  1032.     option to the sending program.  Although this two character sequence works
  1033.     well on single process micros in direct communication, timesharing systems
  1034.     and packet switched networks can separate the successive characters by
  1035.     several seconds, rendering this method unreliable.
  1036.  
  1037.     Sending programs may detect the CK sequence if the operating enviornment
  1038.     does not preclude reliable implementation.
  1039.  
  1040.     Instead of the standard YMODEM file length, KMD and IMP transmit the CP/M
  1041.     record count in the last two bytes of the header block.
  1042.  
  1043.  
  1044.  
  1045.  
  1046.  
  1047.  
  1048.  
  1049.  
  1050.  
  1051.  
  1052.     Chapter 6                                     XMODEM Protocol Enhancements
  1053.  
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.     X/YMODEM Protocol Reference      10-27-87                               17
  1061.  
  1062.  
  1063.  
  1064.     6.  YMODEM-g File Transmission
  1065.  
  1066.     Developing technology is providing phone line data transmission at ever
  1067.     higher speeds using very specialized techniques.  These high speed modems,
  1068.     as well as session protocols such as X.PC, provide high speed, nearly
  1069.     error free communications at the expense of considerably increased delay
  1070.     time.
  1071.  
  1072.     This delay time is moderate compared to human interactions, but it
  1073.     cripples the throughput of most error correcting protocols.
  1074.  
  1075.     The g option to YMODEM has proven effective under these circumstances.
  1076.     The g option is driven by the receiver, which initiates the batch transfer
  1077.     by transmitting a G instead of C.  When the sender recognizes the G, it
  1078.     bypasses the usual wait for an ACK to each transmitted block, sending
  1079.     succeeding blocks at full speed, subject to XOFF/XON or other flow control
  1080.     exerted by the medium.
  1081.  
  1082.     The sender expects an inital G to initiate the transmission of a
  1083.     particular file, and also expects an ACK on the EOT sent at the end of
  1084.     each file.  This synchronization allows the receiver time to open and
  1085.     close files as necessary.
  1086.  
  1087.     If an error is detected in a YMODEM-g transfer, the receiver aborts the
  1088.     transfer with the multiple CAN abort sequence.  The ZMODEM protocol should
  1089.     be used in applications that require both streaming throughput and error
  1090.     recovery.
  1091.  
  1092.             Figure 7.  YMODEM-g Transmission Session
  1093.  
  1094.             SENDER                                  RECEIVER
  1095.                                                     "sb foo.*<CR>"
  1096.             "sending in batch mode etc..."
  1097.                                                     G (command:rb -g)
  1098.             SOH 00 FF foo.c NUL[123] CRC CRC
  1099.                                                     G
  1100.             SOH 01 FE Data[128] CRC CRC
  1101.             STX 02 FD Data[1024] CRC CRC
  1102.             SOH 03 FC Data[128] CRC CRC
  1103.             SOH 04 FB Data[100] CPMEOF[28] CRC CRC
  1104.             EOT
  1105.                                                     ACK
  1106.                                                     G
  1107.             SOH 00 FF NUL[128] CRC CRC
  1108.  
  1109.  
  1110.  
  1111.  
  1112.  
  1113.  
  1114.  
  1115.  
  1116.  
  1117.  
  1118.     Chapter 6                                     XMODEM Protocol Enhancements
  1119.  
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.     X/YMODEM Protocol Reference      10-27-87                               18
  1127.  
  1128.  
  1129.  
  1130.     7.  XMODEM PROTOCOL OVERVIEW
  1131.  
  1132.     8/9/82 by Ward Christensen.
  1133.  
  1134.     I will maintain a master copy of this.  Please pass on changes or
  1135.     suggestions via CBBS/Chicago at (312) 545-8086, CBBS/CPMUG (312) 849-1132
  1136.     or by voice at (312) 849-6279.
  1137.  
  1138.     7.1  Definitions
  1139.  
  1140.       <soh> 01H
  1141.       <eot> 04H
  1142.       <ack> 06H
  1143.       <nak> 15H
  1144.       <can> 18H
  1145.       <C>   43H
  1146.  
  1147.  
  1148.     7.2  Transmission Medium Level Protocol
  1149.  
  1150.     Asynchronous, 8 data bits, no parity, one stop bit.
  1151.  
  1152.     The protocol imposes no restrictions on the contents of the data being
  1153.     transmitted.  No control characters are looked for in the 128-byte data
  1154.     messages.  Absolutely any kind of data may be sent - binary, ASCII, etc.
  1155.     The protocol has not formally been adopted to a 7-bit environment for the
  1156.     transmission of ASCII-only (or unpacked-hex) data , although it could be
  1157.     simply by having both ends agree to AND the protocol-dependent data with
  1158.     7F hex before validating it.  I specifically am referring to the checksum,
  1159.     and the block numbers and their ones- complement.
  1160.  
  1161.     Those wishing to maintain compatibility of the CP/M file structure, i.e.
  1162.     to allow modemming ASCII files to or from CP/M systems should follow this
  1163.     data format:
  1164.  
  1165.        + ASCII tabs used (09H); tabs set every 8.
  1166.  
  1167.        + Lines terminated by CR/LF (0DH 0AH)
  1168.  
  1169.        + End-of-file indicated by ^Z, 1AH.  (one or more)
  1170.  
  1171.        + Data is variable length, i.e. should be considered a continuous
  1172.          stream of data bytes, broken into 128-byte chunks purely for the
  1173.          purpose of transmission.
  1174.  
  1175.        + A CP/M "peculiarity": If the data ends exactly on a 128-byte
  1176.          boundary, i.e. CR in 127, and LF in 128, a subsequent sector
  1177.          containing the ^Z EOF character(s) is optional, but is preferred.
  1178.          Some utilities or user programs still do not handle EOF without ^Zs.
  1179.  
  1180.  
  1181.  
  1182.  
  1183.  
  1184.     Chapter 7                                         Xmodem Protocol Overview
  1185.  
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.     X/YMODEM Protocol Reference      10-27-87                               19
  1193.  
  1194.  
  1195.  
  1196.        + The last block sent is no different from others, i.e.  there is no
  1197.          "short block".
  1198.                   Figure 8.  XMODEM Message Block Level Protocol
  1199.  
  1200.     Each block of the transfer looks like:
  1201.           <SOH><blk #><255-blk #><--128 data bytes--><cksum>
  1202.     in which:
  1203.     <SOH>         = 01 hex
  1204.     <blk #>       = binary number, starts at 01 increments by 1, and
  1205.                     wraps 0FFH to 00H (not to 01)
  1206.     <255-blk #>   = blk # after going thru 8080 "CMA" instr, i.e.
  1207.                     each bit complemented in the 8-bit block number.
  1208.                     Formally, this is the "ones complement".
  1209.     <cksum>       = the sum of the data bytes only.  Toss any carry.
  1210.  
  1211.     7.3  File Level Protocol
  1212.  
  1213.     7.3.1  Common_to_Both_Sender_and_Receiver
  1214.     All errors are retried 10 times.  For versions running with an operator
  1215.     (i.e. NOT with XMODEM), a message is typed after 10 errors asking the
  1216.     operator whether to "retry or quit".
  1217.  
  1218.     Some versions of the protocol use <can>, ASCII ^X, to cancel transmission.
  1219.     This was never adopted as a standard, as having a single "abort" character
  1220.     makes the transmission susceptible to false termination due to an <ack>
  1221.     <nak> or <soh> being corrupted into a <can> and aborting transmission.
  1222.  
  1223.     The protocol may be considered "receiver driven", that is, the sender need
  1224.     not automatically re-transmit, although it does in the current
  1225.     implementations.
  1226.  
  1227.  
  1228.     7.3.2  Receive_Program_Considerations
  1229.     The receiver has a 10-second timeout.  It sends a <nak> every time it
  1230.     times out.  The receiver's first timeout, which sends a <nak>, signals the
  1231.     transmitter to start.  Optionally, the receiver could send a <nak>
  1232.     immediately, in case the sender was ready.  This would save the initial 10
  1233.     second timeout.  However, the receiver MUST continue to timeout every 10
  1234.     seconds in case the sender wasn't ready.
  1235.  
  1236.     Once into a receiving a block, the receiver goes into a one-second timeout
  1237.     for each character and the checksum.  If the receiver wishes to <nak> a
  1238.     block for any reason (invalid header, timeout receiving data), it must
  1239.     wait for the line to clear.  See "programming tips" for ideas
  1240.  
  1241.     Synchronizing:  If a valid block number is received, it will be: 1) the
  1242.     expected one, in which case everything is fine; or 2) a repeat of the
  1243.     previously received block.  This should be considered OK, and only
  1244.     indicates that the receivers <ack> got glitched, and the sender re-
  1245.     transmitted; 3) any other block number indicates a fatal loss of
  1246.     synchronization, such as the rare case of the sender getting a line-glitch
  1247.  
  1248.  
  1249.  
  1250.     Chapter 7                                         Xmodem Protocol Overview
  1251.  
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.     X/YMODEM Protocol Reference      10-27-87                               20
  1259.  
  1260.  
  1261.  
  1262.     that looked like an <ack>.  Abort the transmission, sending a <can>
  1263.  
  1264.  
  1265.     7.3.3  Sending_program_considerations
  1266.     While waiting for transmission to begin, the sender has only a single very
  1267.     long timeout, say one minute.  In the current protocol, the sender has a
  1268.     10 second timeout before retrying.  I suggest NOT doing this, and letting
  1269.     the protocol be completely receiver-driven.  This will be compatible with
  1270.     existing programs.
  1271.  
  1272.     When the sender has no more data, it sends an <eot>, and awaits an <ack>,
  1273.     resending the <eot> if it doesn't get one.  Again, the protocol could be
  1274.     receiver-driven, with the sender only having the high-level 1-minute
  1275.     timeout to abort.
  1276.  
  1277.  
  1278.     Here is a sample of the data flow, sending a 3-block message.  It includes
  1279.     the two most common line hits - a garbaged block, and an <ack> reply
  1280.     getting garbaged.  <xx> represents the checksum byte.
  1281.  
  1282.                   Figure 9.  Data flow including Error Recovery
  1283.  
  1284.     SENDER                                  RECEIVER
  1285.                                   times out after 10 seconds,
  1286.                                   <---              <nak>
  1287.     <soh> 01 FE -data- <xx>       --->
  1288.                                   <---              <ack>
  1289.     <soh> 02 FD -data- xx         --->       (data gets line hit)
  1290.                                   <---              <nak>
  1291.     <soh> 02 FD -data- xx         --->
  1292.                                   <---              <ack>
  1293.     <soh> 03 FC -data- xx         --->
  1294.     (ack gets garbaged)           <---              <ack>
  1295.     <soh> 03 FC -data- xx         --->              <ack>
  1296.     <eot>                         --->
  1297.                                   <---       <anything except ack>
  1298.     <eot>                         --->
  1299.                                   <---              <ack>
  1300.     (finished)
  1301.  
  1302.     7.4  Programming Tips
  1303.  
  1304.        + The character-receive subroutine should be called with a parameter
  1305.          specifying the number of seconds to wait.  The receiver should first
  1306.          call it with a time of 10, then <nak> and try again, 10 times.
  1307.  
  1308.          After receiving the <soh>, the receiver should call the character
  1309.          receive subroutine with a 1-second timeout, for the remainder of the
  1310.          message and the <cksum>.  Since they are sent as a continuous stream,
  1311.          timing out of this implies a serious like glitch that caused, say,
  1312.          127 characters to be seen instead of 128.
  1313.  
  1314.  
  1315.  
  1316.     Chapter 7                                         Xmodem Protocol Overview
  1317.  
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.     X/YMODEM Protocol Reference      10-27-87                               21
  1325.  
  1326.  
  1327.  
  1328.        + When the receiver wishes to <nak>, it should call a "PURGE"
  1329.          subroutine, to wait for the line to clear.  Recall the sender tosses
  1330.          any characters in its UART buffer immediately upon completing sending
  1331.          a block, to ensure no glitches were mis- interpreted.
  1332.  
  1333.          The most common technique is for "PURGE" to call the character
  1334.          receive subroutine, specifying a 1-second timeout,[1] and looping
  1335.          back to PURGE until a timeout occurs.  The <nak> is then sent,
  1336.          ensuring the other end will see it.
  1337.  
  1338.        + You may wish to add code recommended by John Mahr to your character
  1339.          receive routine - to set an error flag if the UART shows framing
  1340.          error, or overrun.  This will help catch a few more glitches - the
  1341.          most common of which is a hit in the high bits of the byte in two
  1342.          consecutive bytes.  The <cksum> comes out OK since counting in 1-byte
  1343.          produces the same result of adding 80H + 80H as with adding 00H +
  1344.          00H.
  1345.  
  1346.  
  1347.  
  1348.  
  1349.  
  1350.  
  1351.  
  1352.  
  1353.  
  1354.  
  1355.  
  1356.  
  1357.  
  1358.  
  1359.  
  1360.  
  1361.  
  1362.  
  1363.  
  1364.  
  1365.  
  1366.  
  1367.  
  1368.  
  1369.  
  1370.  
  1371.  
  1372.  
  1373.  
  1374.  
  1375.     __________
  1376.  
  1377.      1. These times should be adjusted for use with timesharing systems.
  1378.  
  1379.  
  1380.  
  1381.  
  1382.     Chapter 7                                         Xmodem Protocol Overview
  1383.  
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.     X/YMODEM Protocol Reference      10-27-87                               22
  1391.  
  1392.  
  1393.  
  1394.     8.  XMODEM/CRC Overview
  1395.  
  1396.     Original 1/13/85 by John Byrns -- CRC option.
  1397.  
  1398.     Please pass on any reports of errors in this document or suggestions for
  1399.     improvement to me via Ward's/CBBS at (312) 849-1132, or by voice at (312)
  1400.     885-1105.
  1401.  
  1402.     The CRC used in the Modem Protocol is an alternate form of block check
  1403.     which provides more robust error detection than the original checksum.
  1404.     Andrew S. Tanenbaum says in his book, Computer Networks, that the CRC-
  1405.     CCITT used by the Modem Protocol will detect all single and double bit
  1406.     errors, all errors with an odd number of bits, all burst errors of length
  1407.     16 or less, 99.997% of 17-bit error bursts, and 99.998% of 18-bit and
  1408.     longer bursts.[1]
  1409.  
  1410.     The changes to the Modem Protocol to replace the checksum with the CRC are
  1411.     straight forward. If that were all that we did we would not be able to
  1412.     communicate between a program using the old checksum protocol and one
  1413.     using the new CRC protocol. An initial handshake was added to solve this
  1414.     problem. The handshake allows a receiving program with CRC capability to
  1415.     determine whether the sending program supports the CRC option, and to
  1416.     switch it to CRC mode if it does. This handshake is designed so that it
  1417.     will work properly with programs which implement only the original
  1418.     protocol. A description of this handshake is presented in section 10.
  1419.  
  1420.                 Figure 10.  Message Block Level Protocol, CRC mode
  1421.  
  1422.     Each block of the transfer in CRC mode looks like:
  1423.          <SOH><blk #><255-blk #><--128 data bytes--><CRC hi><CRC lo>
  1424.     in which:
  1425.     <SOH>        = 01 hex
  1426.     <blk #>      = binary number, starts at 01 increments by 1, and
  1427.                    wraps 0FFH to 00H (not to 01)
  1428.     <255-blk #>  = ones complement of blk #.
  1429.     <CRC hi>     = byte containing the 8 hi order coefficients of the CRC.
  1430.     <CRC lo>     = byte containing the 8 lo order coefficients of the CRC.
  1431.  
  1432.     8.1  CRC Calculation
  1433.  
  1434.     8.1.1  Formal_Definition
  1435.     To calculate the 16 bit CRC the message bits are considered to be the
  1436.     coefficients of a polynomial. This message polynomial is first multiplied
  1437.     by X^16 and then divided by the generator polynomial (X^16 + X^12 + X^5 +
  1438.  
  1439.  
  1440.     __________
  1441.  
  1442.      1. This reliability figure is misleading because XMODEM's critical
  1443.         supervisory functions are not protected by this CRC.
  1444.  
  1445.  
  1446.  
  1447.  
  1448.     Chapter 8                                         Xmodem Protocol Overview
  1449.  
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.     X/YMODEM Protocol Reference      10-27-87                               23
  1457.  
  1458.  
  1459.  
  1460.     1) using modulo two arithmetic. The remainder left after the division is
  1461.     the desired CRC. Since a message block in the Modem Protocol is 128 bytes
  1462.     or 1024 bits, the message polynomial will be of order X^1023. The hi order
  1463.     bit of the first byte of the message block is the coefficient of X^1023 in
  1464.     the message polynomial.  The lo order bit of the last byte of the message
  1465.     block is the coefficient of X^0 in the message polynomial.
  1466.  
  1467.                Figure 11.  Example of CRC Calculation written in C
  1468.  
  1469.     The following XMODEM crc routine is taken from "rbsb.c".  Please refer to
  1470.     the source code for these programs (contained in RZSZ.ZOO) for usage.  A
  1471.     fast table driven version is also included in this file.
  1472.  
  1473.     /* update CRC */
  1474.     unsigned short
  1475.     updcrc(c, crc)
  1476.     register c;
  1477.     register unsigned crc;
  1478.     {
  1479.             register count;
  1480.  
  1481.             for (count=8; --count>=0;) {
  1482.                     if (crc & 0x8000) {
  1483.                             crc <<= 1;
  1484.                             crc += (((c<<=1) & 0400)  !=  0);
  1485.                             crc ^= 0x1021;
  1486.                     }
  1487.                     else {
  1488.                             crc <<= 1;
  1489.                             crc += (((c<<=1) & 0400)  !=  0);
  1490.                     }
  1491.             }
  1492.             return crc;
  1493.     }
  1494.  
  1495.     8.2  CRC File Level Protocol Changes
  1496.  
  1497.     8.2.1  Common_to_Both_Sender_and_Receiver
  1498.     The only change to the File Level Protocol for the CRC option is the
  1499.     initial handshake which is used to determine if both the sending and the
  1500.     receiving programs support the CRC mode. All Modem Programs should support
  1501.     the checksum mode for compatibility with older versions.  A receiving
  1502.     program that wishes to receive in CRC mode implements the mode setting
  1503.     handshake by sending a <C> in place of the initial <nak>.  If the sending
  1504.     program supports CRC mode it will recognize the <C> and will set itself
  1505.     into CRC mode, and respond by sending the first block as if a <nak> had
  1506.     been received. If the sending program does not support CRC mode it will
  1507.     not respond to the <C> at all. After the receiver has sent the <C> it will
  1508.     wait up to 3 seconds for the <soh> that starts the first block. If it
  1509.     receives a <soh> within 3 seconds it will assume the sender supports CRC
  1510.     mode and will proceed with the file exchange in CRC mode. If no <soh> is
  1511.  
  1512.  
  1513.  
  1514.     Chapter 8                                         Xmodem Protocol Overview
  1515.  
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.     X/YMODEM Protocol Reference      10-27-87                               24
  1523.  
  1524.  
  1525.  
  1526.     received within 3 seconds the receiver will switch to checksum mode, send
  1527.     a <nak>, and proceed in checksum mode. If the receiver wishes to use
  1528.     checksum mode it should send an initial <nak> and the sending program
  1529.     should respond to the <nak> as defined in the original Modem Protocol.
  1530.     After the mode has been set by the initial <C> or <nak> the protocol
  1531.     follows the original Modem Protocol and is identical whether the checksum
  1532.     or CRC is being used.
  1533.  
  1534.  
  1535.     8.2.2  Receive_Program_Considerations
  1536.     There are at least 4 things that can go wrong with the mode setting
  1537.     handshake.
  1538.  
  1539.       1.  the initial <C> can be garbled or lost.
  1540.  
  1541.       2.  the initial <soh> can be garbled.
  1542.  
  1543.       3.  the initial <C> can be changed to a <nak>.
  1544.  
  1545.       4.  the initial <nak> from a receiver which wants to receive in checksum
  1546.           can be changed to a <C>.
  1547.  
  1548.     The first problem can be solved if the receiver sends a second <C> after
  1549.     it times out the first time. This process can be repeated several times.
  1550.     It must not be repeated too many times before sending a <nak> and
  1551.     switching to checksum mode or a sending program without CRC support may
  1552.     time out and abort. Repeating the <C> will also fix the second problem if
  1553.     the sending program cooperates by responding as if a <nak> were received
  1554.     instead of ignoring the extra <C>.
  1555.  
  1556.     It is possible to fix problems 3 and 4 but probably not worth the trouble
  1557.     since they will occur very infrequently. They could be fixed by switching
  1558.     modes in either the sending or the receiving program after a large number
  1559.     of successive <nak>s. This solution would risk other problems however.
  1560.  
  1561.  
  1562.     8.2.3  Sending_Program_Considerations
  1563.     The sending program should start in the checksum mode. This will insure
  1564.     compatibility with checksum only receiving programs. Anytime a <C> is
  1565.     received before the first <nak> or <ack> the sending program should set
  1566.     itself into CRC mode and respond as if a <nak> were received. The sender
  1567.     should respond to additional <C>s as if they were <nak>s until the first
  1568.     <ack> is received. This will assist the receiving program in determining
  1569.     the correct mode when the <soh> is lost or garbled. After the first <ack>
  1570.     is received the sending program should ignore <C>s.
  1571.  
  1572.  
  1573.  
  1574.  
  1575.  
  1576.  
  1577.  
  1578.  
  1579.  
  1580.     Chapter 8                                         Xmodem Protocol Overview
  1581.  
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.     X/YMODEM Protocol Reference      10-27-87                               25
  1589.  
  1590.  
  1591.  
  1592.     8.3  Data Flow Examples with CRC Option
  1593.  
  1594.     Here is a data flow example for the case where the receiver requests
  1595.     transmission in the CRC mode but the sender does not support the CRC
  1596.     option. This example also includes various transmission errors.  <xx>
  1597.     represents the checksum byte.
  1598.  
  1599.           Figure 12.  Data Flow: Receiver has CRC Option, Sender Doesn't
  1600.  
  1601.     SENDER                                        RECEIVER
  1602.                             <---                <C>
  1603.                                     times out after 3 seconds,
  1604.                             <---                <C>
  1605.                                     times out after 3 seconds,
  1606.                             <---                <C>
  1607.                                     times out after 3 seconds,
  1608.                             <---                <C>
  1609.                                     times out after 3 seconds,
  1610.                             <---                <nak>
  1611.     <soh> 01 FE -data- <xx> --->
  1612.                             <---                <ack>
  1613.     <soh> 02 FD -data- <xx> --->        (data gets line hit)
  1614.                             <---                <nak>
  1615.     <soh> 02 FD -data- <xx> --->
  1616.                             <---                <ack>
  1617.     <soh> 03 FC -data- <xx> --->
  1618.        (ack gets garbaged)  <---                <ack>
  1619.                                     times out after 10 seconds,
  1620.                             <---                <nak>
  1621.     <soh> 03 FC -data- <xx> --->
  1622.                             <---                <ack>
  1623.     <eot>                   --->
  1624.                             <---                <ack>
  1625.  
  1626.     Here is a data flow example for the case where the receiver requests
  1627.     transmission in the CRC mode and the sender supports the CRC option.  This
  1628.     example also includes various transmission errors.  <xxxx> represents the
  1629.     2 CRC bytes.
  1630.  
  1631.  
  1632.  
  1633.  
  1634.  
  1635.  
  1636.  
  1637.  
  1638.  
  1639.  
  1640.  
  1641.  
  1642.  
  1643.  
  1644.  
  1645.  
  1646.     Chapter 8                                         Xmodem Protocol Overview
  1647.  
  1648.  
  1649.  
  1650.  
  1651.  
  1652.  
  1653.  
  1654.     X/YMODEM Protocol Reference      10-27-87                               26
  1655.  
  1656.  
  1657.  
  1658.                Figure 13.  Receiver and Sender Both have CRC Option
  1659.  
  1660.     SENDER                                       RECEIVER
  1661.                               <---                 <C>
  1662.     <soh> 01 FE -data- <xxxx> --->
  1663.                               <---                 <ack>
  1664.     <soh> 02 FD -data- <xxxx> --->         (data gets line hit)
  1665.                               <---                 <nak>
  1666.     <soh> 02 FD -data- <xxxx> --->
  1667.                               <---                 <ack>
  1668.     <soh> 03 FC -data- <xxxx> --->
  1669.     (ack gets garbaged)       <---                 <ack>
  1670.                                          times out after 10 seconds,
  1671.                               <---                 <nak>
  1672.     <soh> 03 FC -data- <xxxx> --->
  1673.                               <---                 <ack>
  1674.     <eot>                     --->
  1675.                               <---                 <ack>
  1676.  
  1677.  
  1678.  
  1679.  
  1680.  
  1681.  
  1682.  
  1683.  
  1684.  
  1685.  
  1686.  
  1687.  
  1688.  
  1689.  
  1690.  
  1691.  
  1692.  
  1693.  
  1694.  
  1695.  
  1696.  
  1697.  
  1698.  
  1699.  
  1700.  
  1701.  
  1702.  
  1703.  
  1704.  
  1705.  
  1706.  
  1707.  
  1708.  
  1709.  
  1710.  
  1711.  
  1712.     Chapter 8                                         Xmodem Protocol Overview
  1713.  
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.     X/YMODEM Protocol Reference      10-27-87                               27
  1721.  
  1722.  
  1723.  
  1724.     9.  MORE INFORMATION
  1725.  
  1726.     Please contact Omen Technology for troff source files and typeset copies
  1727.     of this document.
  1728.  
  1729.  
  1730.     9.1  TeleGodzilla Bulletin Board
  1731.  
  1732.     More information may be obtained by calling TeleGodzilla at 503-621-3746.
  1733.     Speed detection is automatic for 1200, 2400 and 19200(Telebit PEP) bps.
  1734.     TrailBlazer modem users may issue the TeleGodzilla trailblazer command to
  1735.     swith to 19200 bps once they have logged in.
  1736.  
  1737.     Interesting files include RZSZ.ZOO (C source code), YZMODEM.ZOO (Official
  1738.     XMODEM, YMODEM, and ZMODEM protocol descriptions), ZCOMMEXE.ARC,
  1739.     ZCOMMDOC.ARC, and ZCOMMHLP.ARC (PC-DOS shareware comm program with XMODEM,
  1740.     True YMODEM(TM), ZMODEM, Kermit Sliding Windows, Telink, MODEM7 Batch,
  1741.     script language, etc.).
  1742.  
  1743.  
  1744.     9.2  Unix UUCP Access
  1745.  
  1746.     UUCP sites can obtain the current version of this file with
  1747.                      uucp omen!/u/caf/public/ymodem.doc /tmp
  1748.     A continually updated list of available files is stored in
  1749.     /usr/spool/uucppublic/FILES.  When retrieving these files with uucp,
  1750.     remember that the destination directory on your system must be writeable
  1751.     by anyone, or the UUCP transfer will fail.
  1752.  
  1753.     The following L.sys line calls TeleGodzilla (Pro-YAM in host operation).
  1754.     TeleGodzilla determines the incoming speed automatically.
  1755.  
  1756.     In response to "Name Please:" uucico gives the Pro-YAM "link" command as a
  1757.     user name.  The password (Giznoid) controls access to the Xenix system
  1758.     connected to the IBM PC's other serial port.  Communications between
  1759.     Pro-YAM and Xenix use 9600 bps; YAM converts this to the caller's speed.
  1760.  
  1761.     Finally, the calling uucico logs in as uucp.
  1762.  
  1763.     omen Any ACU 2400 1-503-621-3746 se:--se: link ord: Giznoid in:--in: uucp
  1764.  
  1765.  
  1766.  
  1767.     10.  REVISIONS
  1768.  
  1769.     10-27-87 Optional fields added for number of files remaining to be sent
  1770.     and total number of bytes remaining to be sent.
  1771.     10-18-87 Flow control discussion added to 1024 byte block descritpion,
  1772.     minor revisions for clarity per user comments.
  1773.     8-03-87 Revised for clarity.
  1774.     5-31-1987 emphasizes minimum requirements for YMODEM, and updates
  1775.  
  1776.  
  1777.  
  1778.     Chapter 10                                        Xmodem Protocol Overview
  1779.  
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.     X/YMODEM Protocol Reference      10-27-87                               28
  1787.  
  1788.  
  1789.  
  1790.     information on accessing files.
  1791.     9-11-1986 clarifies nomenclature and some minor points.
  1792.     The April 15 1986 edition clarifies some points concerning CRC
  1793.     calculations and spaces in the header.
  1794.  
  1795.  
  1796.     11.  YMODEM Programs
  1797.  
  1798.     ZCOMM, A shareware little brother to Professional-YAM, is available as
  1799.     ZCOMMEXE.ARC on TeleGodzilla and other bulletin board systems.  ZCOMM may
  1800.     be used to test YMODEM amd ZMODEM implementations.
  1801.  
  1802.     Unix programs supporting YMODEM are available on TeleGodzilla in RZSZ.ZOO.
  1803.     This ZOO archive includes a ZCOMM/Pro-YAM/PowerCom script ZUPL.T to upload
  1804.     a bootstrap program MINIRB.C, compile it, and then upload the rest of the
  1805.     files using the compiled MINIRB.  Most Unix like systems are supported,
  1806.     including V7, Xenix, Sys III, 4.2 BSD, SYS V, Idris, Coherent, and
  1807.     Regulus.
  1808.  
  1809.     A version for VAX-VMS is available in VRBSB.SHQ.
  1810.  
  1811.     Irv Hoff has added 1k blocks and basic YMODEM batch transfers to the KMD
  1812.     and IMP series programs, which replace the XMODEM and MODEM7/MDM7xx series
  1813.     respectively.  Overlays are available for a wide variety of CP/M systems.
  1814.  
  1815.     Questions about Professional-YAM communications software may be directed
  1816.     to:
  1817.          Chuck Forsberg
  1818.          Omen Technology Inc
  1819.          17505-V Sauvie Island Road
  1820.          Portland Oregon 97231
  1821.          VOICE: 503-621-3406 :VOICE
  1822.          Modem: 503-621-3746 Speed: 19200(Telebit PEP),2400,1200,300
  1823.          Usenet: ...!tektronix!reed!omen!caf
  1824.          CompuServe: 70007,2304
  1825.          GEnie: CAF
  1826.  
  1827.     Unlike ZMODEM and Kermit, XMODEM and YMODEM place obstacles in the path of
  1828.     a reliable high performance implementation, evidenced by poor reliability
  1829.     under stress of the industry leaders' XMODEM and YMODEM programs.  Omen
  1830.     Technology provides consulting and other services to those wishing to
  1831.     implement XMODEM, YMODEM, and ZMODEM with state of the art features and
  1832.     reliability.
  1833.  
  1834.  
  1835.  
  1836.  
  1837.  
  1838.  
  1839.  
  1840.  
  1841.  
  1842.  
  1843.  
  1844.     Chapter 11                                        Xmodem Protocol Overview
  1845.  
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.  
  1853.  
  1854.  
  1855.  
  1856.                                      CONTENTS
  1857.  
  1858.  
  1859.      1.  TOWER OF BABEL...................................................   2
  1860.          1.1  Definitions.................................................   2
  1861.  
  1862.      2.  YMODEM MINIMUM REQUIREMENTS......................................   4
  1863.  
  1864.      3.  WHY YMODEM?......................................................   5
  1865.          3.1  Some Messages from the Pioneer..............................   6
  1866.  
  1867.      4.  XMODEM PROTOCOL ENHANCEMENTS.....................................   9
  1868.          4.1  Graceful Abort..............................................   9
  1869.          4.2  CRC-16 Option...............................................   9
  1870.          4.3  XMODEM-1k 1024 Byte Block...................................  10
  1871.  
  1872.      5.  YMODEM Batch File Transmission...................................  12
  1873.          5.1  KMD/IMP Exceptions to YMODEM................................  16
  1874.  
  1875.      6.  YMODEM-g File Transmission.......................................  17
  1876.  
  1877.      7.  XMODEM PROTOCOL OVERVIEW.........................................  18
  1878.          7.1  Definitions.................................................  18
  1879.          7.2  Transmission Medium Level Protocol..........................  18
  1880.          7.3  File Level Protocol.........................................  19
  1881.          7.4  Programming Tips............................................  20
  1882.  
  1883.      8.  XMODEM/CRC Overview..............................................  22
  1884.          8.1  CRC Calculation.............................................  22
  1885.          8.2  CRC File Level Protocol Changes.............................  23
  1886.          8.3  Data Flow Examples with CRC Option..........................  25
  1887.  
  1888.      9.  MORE INFORMATION.................................................  27
  1889.          9.1  TeleGodzilla Bulletin Board.................................  27
  1890.          9.2  Unix UUCP Access............................................  27
  1891.  
  1892.     10.  REVISIONS........................................................  27
  1893.  
  1894.     11.  YMODEM Programs..................................................  28
  1895.  
  1896.  
  1897.  
  1898.  
  1899.  
  1900.  
  1901.  
  1902.  
  1903.  
  1904.  
  1905.  
  1906.  
  1907.  
  1908.  
  1909.  
  1910.                                       - i -
  1911.  
  1912.  
  1913.  
  1914.  
  1915.  
  1916.  
  1917.  
  1918.  
  1919.  
  1920.  
  1921.  
  1922.  
  1923.  
  1924.  
  1925.                                  LIST OF FIGURES
  1926.  
  1927.  
  1928.      Figure 1.  XMODEM-1k Blocks..........................................  11
  1929.  
  1930.      Figure 2.  Mixed 1024 and 128 byte Blocks............................  11
  1931.  
  1932.      Figure 3.  YMODEM Batch Transmission Session.........................  15
  1933.  
  1934.      Figure 4.  YMODEM Batch Transmission Session-1k Blocks...............  15
  1935.  
  1936.      Figure 5.  YMODEM Filename block transmitted by sz...................  16
  1937.  
  1938.      Figure 6.  YMODEM Header Information and Features....................  16
  1939.  
  1940.      Figure 7.  YMODEM-g Transmission Session.............................  17
  1941.  
  1942.      Figure 8.  XMODEM Message Block Level Protocol.......................  19
  1943.  
  1944.      Figure 9.  Data flow including Error Recovery........................  20
  1945.  
  1946.     Figure 10.  Message Block Level Protocol, CRC mode....................  22
  1947.  
  1948.     Figure 11.  Example of CRC Calculation written in C...................  23
  1949.  
  1950.     Figure 12.  Data Flow: Receiver has CRC Option, Sender Doesn't........  25
  1951.  
  1952.     Figure 13.  Receiver and Sender Both have CRC Option..................  26
  1953.  
  1954.  
  1955.  
  1956.  
  1957.  
  1958.  
  1959.  
  1960.  
  1961.  
  1962.  
  1963.  
  1964.  
  1965.  
  1966.  
  1967.  
  1968.  
  1969.  
  1970.  
  1971.  
  1972.  
  1973.  
  1974.  
  1975.  
  1976.                                       - ii -
  1977.  
  1978.  
  1979.  
  1980.  
  1981.